//
//  CLComponentBuilder.m
//  ComponentLinkDemo
//
//  Created by zhenby on 2017/2/24.
//  Copyright © 2017年 zhenby. All rights reserved.
//

#import "CLComponentBuilder.h"
#import "CLComponentXMLParser.h"

@implementation CLComponentBuilder

#pragma mark - Build With Property

+ (id<CLPComponent>)buildComponentWithID:(NSString *)componentID
                               className:(Class)className
                              properties:(NSDictionary *)properties
{
    id<CLPComponent> component = nil;
    
    if (className) {
        id tempObj = [[className alloc] init];
        if ([tempObj conformsToProtocol:@protocol(CLPComponent)]) {
            component = tempObj;
            
            component.componentID = componentID;
            
            [properties enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
                if ([key isKindOfClass:[NSString class]]) {
                    [(NSObject *)component setValue:obj forKey:key];
                } else {
                    // 异常处理
                }
            }];
        }
    }
    
    return component;
}



#pragma mark - Build With XML

+ (id<CLPViewComponent>)buildViewComponentWithID:(NSString *)componentID
                                     xmlFilePath:(NSString *)xmlFilePath
{
    return nil;
}

+ (id<CLPViewControllerComponent>)buildViewControllerComponentWithID:(NSString *)componentID
                                                         xmlFilePath:(NSString *)xmlFilePath
{
    return nil;
}



@end
